package com.thb.base.dao.Impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.thb.base.dao.ILabelDao;
import com.thb.base.model.Label;

@Repository
public class LabelDaoImpl implements ILabelDao {
	
	@Autowired
	private JdbcTemplate jTemplate;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public  List<Label> findAll() {
		String sql = "select label_code,name,level from label";
		Object[] arg = new Object[] { };
		
		return jTemplate.query(sql, arg,new RowMapper() {
			public Object mapRow(ResultSet rs, int no) throws SQLException {

				return jsonMapper(rs, no);
			}
		});
	}

	private Label jsonMapper(ResultSet rs, int no) throws SQLException {

		Label vo = new Label();
		vo.setLabelCode(rs.getString("label_code"));
		vo.setName(rs.getString("name"));
		vo.setLevel(rs.getInt("level"));
	
		return vo;
	}

}
